import app
import os
from applications.extensions import db

class dModel(db.Model):
    __abstract__ = True

def tmodel(table):
    cols = db.Table(table, db.metadata, autoload=True, autoload_with=db.engine)
    attrs = {'__tablename__': table}
    for col in cols.columns:
        if col.primary_key:
            attrs[col.name] = db.Column(col.type, primary_key=True)
        else:
            attrs[col.name] = db.Column(col.type)
    return type(table, (dModel, db.Model), attrs)

